import {ProTableProps} from "@ant-design/pro-table";
import {
  RequestLogListProps,
  RequestSuccessLog,
  RequestSuccessLogParams
} from "@/pages/system/tool/requestLog/interfaces";
import columns from "@/pages/system/tool/requestLog/list/Stateless/config/columns";
import {adminSuccessLogList, getStatistics} from "@/services/system/requestLog/api";
import {useEffect, useState} from "react";
import {DataStatisticProps} from "@/pages/system/tool/requestLog/list/Stateless/components/DataStatistic/interfaces";

export default (Stateless: any) => {

  const [statistic, setStatistic] = useState<DataStatisticProps>({})
  const tableProps
    :
    ProTableProps<RequestSuccessLog, RequestSuccessLogParams> = {
    rowSelection: {
      // selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
      // selections: [],
    },
    tableAlertRender: ({selectedRowKeys, selectedRows, onCleanSelected}) => null,
    tableAlertOptionRender: () => null,
    toolBarRender: false,
    options: false,
    tableStyle: {},
    pagination: {defaultPageSize: 10},
    size: "small",
    bordered: true,
    search: false,
    headerTitle: false,
    // @ts-ignore
    columns: columns(),
    request: async (params, sort, filter) => {
      const data: RequestSuccessLogParams = {
        ...params,
        pageNum: params.current as number
      }
      return await adminSuccessLogList(data).then(res => {
        return {
          data: res.data.content,
          success: true,
          total: res.data.totalElements
        }
      })
    },
    rowKey: "id"
  }
  useEffect(() => {
    const id: any = setInterval(() => {
      getStatistics().then(res => {
        setStatistic(res.data)
      })
    }, 1000);
    return () => {
      clearInterval(id)
    }
  })
  const data: any[] = [
    {
      month: "Jan",
      city: "Tokyo",
      temperature: 7
    },
    {
      month: "Jan",
      city: "London",
      temperature: 3.9
    },
    {
      month: "Feb",
      city: "Tokyo",
      temperature: 13
    },
    {
      month: "Feb",
      city: "London",
      temperature: 4.2
    },
    {
      month: "Mar",
      city: "Tokyo",
      temperature: 16.5
    },
    {
      month: "Mar",
      city: "London",
      temperature: 5.7
    },
    {
      month: "Apr",
      city: "Tokyo",
      temperature: 14.5
    },
    {
      month: "Apr",
      city: "London",
      temperature: 8.5
    },
    {
      month: "May",
      city: "Tokyo",
      temperature: 10
    },
    {
      month: "May",
      city: "London",
      temperature: 11.9
    },
    {
      month: "Jun",
      city: "Tokyo",
      temperature: 7.5
    },
    {
      month: "Jun",
      city: "London",
      temperature: 15.2
    },
    {
      month: "Jul",
      city: "Tokyo",
      temperature: 9.2
    },
    {
      month: "Jul",
      city: "London",
      temperature: 17
    },
    {
      month: "Aug",
      city: "Tokyo",
      temperature: 14.5
    },
    {
      month: "Aug",
      city: "London",
      temperature: 16.6
    },
    {
      month: "Sep",
      city: "Tokyo",
      temperature: 9.3
    },
    {
      month: "Sep",
      city: "London",
      temperature: 14.2
    },
    {
      month: "Oct",
      city: "Tokyo",
      temperature: 8.3
    },
    {
      month: "Oct",
      city: "London",
      temperature: 10.3
    },
    {
      month: "Nov",
      city: "Tokyo",
      temperature: 8.9
    },
    {
      month: "Nov",
      city: "London",
      temperature: 5.6
    },
    {
      month: "Dec",
      city: "Tokyo",
      temperature: 5.6
    },
    {
      month: "Dec",
      city: "London",
      temperature: 9.8
    }
  ];


  const statelessProps: RequestLogListProps<RequestSuccessLogParams, RequestSuccessLog> = {
    // @ts-ignore
    tableProps,
    data,
    dataStatistic: statistic
  }
  return (
    <Stateless {...statelessProps}/>
  )
}
